define(function(require,exports,module){
	var $=require("jq");
	var Dialog=require("pz_use_dialog.js");
	var md5 = require("jquery.md5.js");
	var cssDialog=require("/pinzhiV2.0/css/pz-dialog.css");	
	//激活按钮
	var jihuoBtn = $("#js-jihuo-qijiandian");
	jihuoBtn.click(function(){
		var type = $(this).attr("data-type");
		var name = $(this).attr("data-user-name"),
				eV = $(this).attr("data-e"),
			   level = $(this).attr("data-level"),
			   payV = $(this).attr("data-pay"),
			   isPayPsw = $(this).attr("data-paypsw");
		//如果是购买
		if(type == "goumai"){
			
			//如果有支付密码
			var ispsw = "";
			if(isPayPsw=="yes"){
				ispsw = '<li>支付密码：<input type="password" id="js-psw"></li>';
			};
			
			var html ='<div class="pop-html">'+
								'<div class="card"></div>'+
								'<ul>'+
									'<li>开通帐号：'+name+'<i>'+level+'</i></li>'+
									'<li>使用期限：自激活之日起一个自然年有效期</li>'+
									'<li>支付金额：<span>'+payV+'元</span></li>'+
									'<li>E钱包余额：'+eV+'<a href="/vipCenter/depositRecharge.do" target="_blank">充值</a></li>'+ispsw+
									'<li><p id="js-checkbox"><i></i>立即激活</p></li>'+
								'</ul>'+
								'<a id="js-go-jihuo" class="buy-btn" href="javascript:void(0);">立即购买</a>'+
							'</div>';
			
			var tips=new Dialog({
							  height:(isPayPsw=="yes"?580:550),
							  width:408,
							  text:"购会员卡，享尊贵特权",
							  tipsText:html,
							  mask:0.5
					  });
			
			//立即激活和立即购买按钮
			$("#js-checkbox").click(function(){
				$(this).find("i").toggleClass("no");
			});
		
			
			$("#js-go-jihuo").click(function(){
				//如果E钱包余额不足
				if(Number(payV)>Number(eV)){
					var tips0=new Dialog({
							  type:"confirm",
							  text:"提示信息",
							  tipsText:"您的E钱包余额不足，请先充值!",
							  buttonSureText:"去充值", 
							  buttonCancelText:"取消", 
							  callBack:function(){//回调函数
									window.location.href="/vipCenter/depositRecharge.do";
							  },
							  mask:0.5
					  });

					return false;
				};
				
				//如果没有输入支付密码
				if(isPayPsw == "yes"){
					
					var pswInput = $("#js-psw").val();
					if($.trim(pswInput) == ""){
						var tips0=new Dialog({
								  type:"tips",
								  text:"请输入支付密码!"
						  });
						return false;
					}else{
						var pswmd5 = md5(md5($.trim(pswInput)).toUpperCase()+"pinzhi365");
					};
				};
				
				var is = $("#js-checkbox").find("i").hasClass("no")?false:true;

				var tips1=new Dialog({
							  type:"confirm",
							  text:"提示信息",
							  tipsText:"确认购买吗？",
							  buttonSureText:"立即购买", 
							  buttonCancelText:"取消", 
							  callBack:function(){//回调函数
									$.get("/flag/buyShopQualification.do",{isActive:is,pay_pwd:pswmd5},function(data){
										if(data.success === false){
											var tips4=new Dialog({
												  type:"alert",
												  width:240,
												  text:"提示信息",
												  tipsText:data.msg,
												  buttonSureText:"确定",
												  mask:0.2
											});
										} else {
											var tips2=new Dialog({
												  type:"alert",
												  width:240,
												  text:"提示信息",
												  tipsText:"恭喜你！成功购买旗舰店会员资格！",
												  buttonSureText:"确定", 
												  callBack:function(){//回调函数
													window.location.reload();
												  },
												  mask:0.2
											});
										}
									}, "json");
							  },
							  mask:0.2
					  });
				
			});
		
		
		}else if(type == "jihuo"){
			var html ='<div class="pop-html">'+
								'<div class="card"></div>'+
								'<ul>'+
									'<li>尊敬的会员'+name+'</li>'+
									'<li class="txt">您已成功购买旗舰店会员卡，会员卡激活后，即可享受旗舰店会员优惠资格,<em>有效期为一年</em>。</li>'+
								'</ul>'+
								'<a id="js-go-jihuo" class="buy-btn" href="javascript:void(0);">立即激活</a>'+
							'</div>';
			
			var tips=new Dialog({
							  height:500,
							  width:408,
							  text:"激活",
							  tipsText:html,
							  mask:0.5
					  });
			
			$("#js-go-jihuo").click(function(){
				
					var tips1=new Dialog({
										  type:"confirm",
										  text:"提示信息",
										  tipsText:"确认激活吗？",
										  buttonSureText:"激活", 
										  buttonCancelText:"取消", 
										  callBack:function(){//回调函数
												$.get("/flag/activeShopQualification.do",function(data){
													if(data.success === false){
														var tips2=new Dialog({
															  type:"alert",
															  height:150,
															  text:"提示信息",
															  tipsText:data.msg,
															  buttonSureText:"确定",
															  mask:0.5
														});
													} else {
														var tips2=new Dialog({
															  type:"alert",
															  height:150,
															  text:"提示信息",
															  tipsText:"尊敬的会员"+name+",恭喜您成功激活旗舰店会员卡!",
															  buttonSureText:"确定", 
															  callBack:function(){//回调函数
																window.location.reload();
															  },
															  mask:0.5
														});
													}
												}, "json");
										  },
										  mask:0.5
										  });
			});
		};
	
	});
	
});
